using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FrameWork.Source.CMenu_class
{
    class CMenu
    {
        /// <summary>
        /// List item this menu control
        /// </summary>
        private List<CMenuItem> m_pListItem;

        public CMenu()
        {
            m_pListItem = new List<CMenuItem>();
        }

        /// <summary>
        /// Add item to this menu
        /// </summary>
        /// <param name="pItem"></param>
        public void addItem(CMenuItem pItem)
        {
            m_pListItem.Add(pItem);
        }

        /// <summary>
        /// Update our menu
        /// </summary>
        /// <param name="deltaTime"></param>
        public void update(float deltaTime)
        {
            foreach (CMenuItem pItem in m_pListItem)
            {
                pItem.update(deltaTime);
            }
        }

        /// <summary>
        /// Draw our menu into screen
        /// </summary>
        public void draw()
        {
            foreach (CMenuItem pItem in m_pListItem)
            {
                pItem.draw();
            }
        }

        /// <summary>
        /// Get a picking item of this menu
        /// </summary>
        /// <param name="pickX"></param>
        /// <param name="pickY"></param>
        /// <param name="pRefItem"></param>
        /// <returns></returns>
        public bool picking(int pickX, int pickY, ref CMenuItem pRefItem)
        {
            foreach (CMenuItem pItem in m_pListItem)
            {
                if (pItem.picking(pickX, pickY))
                {
                    pRefItem = pItem;
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// Get item of this menu based on index
        /// </summary>
        /// <param name="index">Item index</param>
        /// <param name="pRefItem">Reference pointer to retrieve item</param>
        public void getItem(int index, ref CMenuItem pRefItem)
        {
            foreach (CMenuItem pItem in m_pListItem)
            {
                if (pItem.m_nIndex == index)
                {
                    pRefItem = pItem;
                    return;
                }
            }
        }

        /// <summary>
        /// Get item of this menu based on name
        /// </summary>
        /// <param name="name">Item name</param>
        /// <param name="pRefItem">Reference pointer to retrieve item</param>
        public void getItem(string name, ref CMenuItem pRefItem)
        {
            foreach (CMenuItem pItem in m_pListItem)
            {
                if (pItem.m_strName == name)
                {
                    pRefItem = pItem;
                    return;
                }
            }
        }
    }
}
